//
//  JGHtmlViewController.m
//  WangYLottery
//
//  Created by JJetGu on 15/8/29.
//  Copyright (c) 2015年 JJetGu. All rights reserved.
//

#import "JGHtmlViewController.h"
#import "JGHelp.h"

@interface JGHtmlViewController ()<UIWebViewDelegate>

@end

@implementation JGHtmlViewController

-(void)loadView
{
    self.view = [[UIWebView alloc] init];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleBordered target:self action:@selector(cancle)];
    self.navigationItem.leftBarButtonItem = cancel;
    
    UIWebView *webView = (UIWebView *)self.view;
    
    // 加载资源包里面的Html
    NSURL *url = [[NSBundle mainBundle] URLForResource:self.help.html withExtension:nil];
    NSURLRequest *requst = [NSURLRequest requestWithURL:url];
    webView.delegate = self;
    [webView loadRequest:requst];
}

-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
}

// 加载完网页调用
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *js = [NSString stringWithFormat:@"window.location.href = '#%@';",self.help.ID];
    [webView stringByEvaluatingJavaScriptFromString:js];
    
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}


- (void)cancle
{
    // 回到上一个控制器
    [self dismissViewControllerAnimated:YES completion:nil];
    
}










@end
